package com.cxg.allsys.adminsys.controller;

import com.cxg.allsys.adminsys.pojo.Expert;
import com.cxg.allsys.adminsys.service.IExpertService;
import com.cxg.allsys.adminsys.view.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@Data
@RestController
@RequestMapping("/api/Administration")
@CrossOrigin
public class ExpertController {
    @Autowired
    private IExpertService expertService;
    //分页查询
    @RequestMapping("/pViewPageExpert")
    @ApiOperation(value = "分页查询",notes = "分页查询")
    public PageInfo query(PageInfo<Expert> pageInfo){
        log.info("分页查询controller执行");
        log.info(pageInfo.getQuerStr()+pageInfo.getPageSize()+pageInfo.getPageIndex());
        List<Expert> list=expertService.query(pageInfo.getPageIndex(),pageInfo.getPageSize(),pageInfo.getQuerStr());
        pageInfo.setList(list);
        log.info(pageInfo.toString());
        return pageInfo;
    }
    //根据专家ID查询
    @RequestMapping("/selectByIdExpert")
    @ApiOperation(value = "根据专家ID查询",notes = "根据专家ID查询")
    public Expert selectById(Integer expertId){
        log.info("根据专家ID查询controller执行");
        Expert exp = expertService.selectById(expertId);
        log.info(exp.toString());
        return exp;
    }
    //添加专家
    @RequestMapping("/AddTExpert")
    @ApiOperation(value = "添加专家",notes = "添加专家")
    public boolean save(Expert expert){
        log.info("添加数据controller执行");
        log.info("输入内容打印1"+expert.toString());
        boolean flag=expertService.save(expert);
        log.info(String.valueOf(flag));
        log.info("输入内容打印"+expert.toString());
        if (flag) {
            return true;
        } else {
            return false;
        }
    }
    //修改专家信息
    @RequestMapping("/UpdateExpert")
    @ApiOperation(value = "修改专家信息",notes = "修改专家信息")
    public boolean updateExpert(Expert expert){
        log.info("添加数据controller执行");
        boolean flag=expertService.updateExpert(expert);
        log.info(String.valueOf(flag));
        log.info("输入内容打印"+expert.toString());
        if (flag) {
            return true;
        } else {
            return false;
        }
    }
    //专家状态重置
    @RequestMapping("/UpdateExpertForEditStatus")
    @ApiOperation(value = "专家状态重置",notes = "专家状态重置")
    public boolean updateExpertForEditStatus(Integer expertId,String status){
        log.info("专家状态重置controller执行");
        boolean flag=expertService.updateExpertForEditStatus(expertId,status);
        log.info(String.valueOf(flag));
        log.info("controller层输入内容打印："+"ID:"+expertId+"状态："+status);
        if (flag) {
            return true;
        } else {
            return false;
        }
    }

    //删除专家信息
    @RequestMapping("/DelectExpert")
    @ApiOperation(value = "删除专家信息",notes = "删除专家信息")
    public boolean delectExpert(Expert expert){
        log.info("添加数据controller执行");
        boolean flag=expertService.deleteExpert(expert);
        log.info(String.valueOf(flag));
        log.info("输入内容打印："+expert.toString());
        if (flag) {
            return true;
        } else {
            return false;
        }
    }
}
